//
//  HotScenicCell.swift
//  GroupApp
//
//  Created by 语安 on 16/8/16.
//  Copyright © 2016年 thls.com. All rights reserved.
//

import UIKit

class HotScenicCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate {
    
    var modelArray = [ScenicModel]()
    
    var colView: UICollectionView?

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSizeMake(screenWidth / 2 - 15, 100)
        layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        
        colView = UICollectionView(frame: self.contentView.frame, collectionViewLayout: layout)
        colView?.bounces = false
        colView?.scrollEnabled = false
        colView?.backgroundColor = UIColor.whiteColor()
        colView?.dataSource = self
        colView?.delegate = self
        
        colView?.registerNib(UINib(nibName: "ListCell", bundle: nil), forCellWithReuseIdentifier: "listCell")
        self.addSubview(colView!)
        
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return modelArray.count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("listCell", forIndexPath: indexPath) as! ListCell
        
        if modelArray.count > 0 {
            let model = modelArray[indexPath.item]
            cell.mainImageView.sd_setImageWithURL(NSURL(string: model.mudiPic!), placeholderImage: UIImage(named: "1"))
            cell.nameLabel.text = model.scenicName!
        }
        
        return cell
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
